package com.crm.exception;

import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
/**
 * Class Description:项目中所有RuntimeException的基类，RuntimeException体系包括错误的类型转换、数组越界访问和访问空指针等
 *  try
		{
			InputStream is = formfile.getInputStream();
			InputStreamReader isr = new InputStreamReader(is);
			BufferedReader br = new BufferedReader(isr);
			
			String temp = null;
			while((temp = br.readLine()) != null)
			{
				querykeys.add(temp);
			}
		}
		catch(FileNotFoundException fe)
		{
			throw new SystemException("exception.system.filenotfound");
		}
		catch(IOException ie)
		{
			throw new SystemException("exception.system.io");
		}
 * <pre>
 *  Filename        : SystemException.java 
 *  Date			   : 2008-08-18
 *  Creator         : liuqing
 *  Revised Description 
 *  ----------------------------------------------
 *  ver	revised date	reviser	revised contents
 *  0.1   2008-08-18       liuqing            create
 *  ----------------------------------------------
 *  
 * </pre>
 */
@SuppressWarnings("serial")
public class SystemException extends RuntimeException {
protected Throwable rootCause;  //支持原始异常
	
	private List<SystemException> exceptions =new ArrayList<SystemException>();//支持多样化异常，exceptions属性存放所有嵌套的异常类
	
	private Object values[];   //支持复合式的消息，values属性制定复合式消息中的参数
	
	private String message; //制定消息Key
	
	public SystemException(){
		
	}
	
	public SystemException(String message){
		this.message=message;
	}
	
	public SystemException(Throwable rootCause){
		super(rootCause);
		this.rootCause=rootCause;
	}
	
	public SystemException(String message,Object value){
		super(message);
		this.message=message;
		values=new Object[]{value};
	}
	
	public SystemException(String message,Object[] values){
		super(message);
		this.message=message;
		this.values=values;
	}
	
	public SystemException(String message,Throwable rootCause,Object value){
		super(message);
		this.message=message;
		this.rootCause=rootCause;
		values=new Object[]{value};
	}
	
	public SystemException(String message,Throwable rootCause,Object[] values){
		super(message);
		this.message=message;
		this.rootCause=rootCause;
		this.values=values;
	}
	
	public List getExceptions() {
		return exceptions;
	}
	
	public void addExcpetion(SystemException ex){
		exceptions.add(ex);
	}
	
	public void printStackTrace(){
		super.printStackTrace(System.err);
	}
	
	public void printStackTrace(PrintStream outStream){
		super.printStackTrace(new PrintWriter(outStream));
	}
	
	public void printStackTrace(PrintWriter writer){
		super.printStackTrace(writer);
		if(getRootCause()!=null){
			getRootCause().printStackTrace(writer);
		}
		writer.flush();
	}
	
	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Throwable getRootCause() {
		return rootCause;
	}

	public void setRootCause(Throwable rootCause) {
		this.rootCause = rootCause;
	}

	public Object[] getValues() {
		return values;
	}

	public void setValues(Object[] values) {
		this.values = values;
	}
}
